#!/bin/bash

echo "===start to publish component==="
chmod +x scripts/common_scripts/common.sh
source scripts/common_scripts/common.sh

function work() {
  echo "1. prepare env"
  pip3 install -r scripts/publish_pipeline/publish_by_comment/requirements.txt
  ret=$(python3 scripts/utils/prepare-env.py --gitcode_domain="${gitcode_domain}")
  package=$(echo $ret | jq -r '.package')

  echo "2.prepare the env about docker..."
  cur_path=$(realpath .)
  docker run --rm -v ${cur_path}:/root/repo/ --privileged=true swr.cn-north-4.myhuaweicloud.com/openubmc/ubuntu:${image_version} \
    /bin/bash /root/repo/scripts/publish_pipeline/publish_by_comment/publish-component.sh ${gitcode_username} ${gitcode_token} ${conan_user} ${conan_password} ${package} ||
    {
      echo "Docker command failed with exit code $?"
      exit 1
    }
}

function main() {
  prepare_software
  prepare_git $gitcode_username $gitcode_token
  work
}

main

exit 0